<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<div class="table-scrollable">
	<table class="table table-striped table-hover table-success">
		<thead>
			<tr>
				<th>#</th>
				<th>任务编号</th>
				<th>任务名称</th>
				<th>业务数据</th>
				<th>办理任务</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${list }" var="task" varStatus="vs">
				<tr>
					<td>${vs.count}</td>
					<td>${task.id }</td>
					<td>${task.name }</td>
					<td>${dataMap[task.id] }</td>
					<td> 
						<a href="#" onclick="takeTask(this,'${task.taskDefinitionKey}','${task.id}')" iconCls="icon-edit">
							<i class="glyphicon glyphicon-ok "></i>
						</a>
					</td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
</div>

<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" id="check_modal">
	  <div class="modal-dialog modal-sm" role="document">
	  	<div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 400px; height: 100px;">
		  	<label class="col-md-3 control-label">审核结果:</label>
		  	  <form action="" id="checkForm">
		        <div class="col-md-4">
		        	<div class="input-icon right">
			        	<i class="fa"></i>
			        	<select class="form-control select2" style="padding: 0;" name="check">
			        		<option value="1">通过</option>
			        		<option value="0">不通过</option>
			        	</select>
			        </div>
		        </div>
		       </form>
		      <div class="col-md-3 col-md-offset-3">
		          <button type="button" class="btn btn-primary" onclick="check()">
		          	<spring:message code="btn.save"></spring:message>
		          </button>
	        </div>
		  </div>
	  </div>
</div>

<script type="text/javascript">
	
	function takeTask(obj, key, id) {
		
		if(key == "checkWorkOrderManage") {
			$("#checkForm").attr("action","${webRoot}/task/"+ key +"/"+id);
			
			$("#check_modal").modal(function(){
				backdrop:"static"
			});
			return;
		}
		
		var url = "${webRoot}/task/"+ key +"/"+id;
		var data = {};
		$.post(url, data, function(result){
			if(result.code == 0) {
				layer.msg("办理任务成功!", {shift: 1});
				setTimeout(function(){
					search();
				}, 1200);
				
			}else{
				layer.msg("办理任务失败!", {shift: 6});
			}
		})
	}
	
	function check() {
		
		var url = $("#checkForm").attr("action");
		var check = $("select[name='check']").val();
		
		$.post(url, {"check":check}, function(result){
			if(result.code == 0) {
				layer.msg("操作成功!", {shift: 1});
				setTimeout(function(){
					$("#check_modal").modal('hide');
				}, 1200);
			}else {
				layer.msg("未知错误!", {shift: 6});
			}
		})
		$("#check_modal").on('hidden.bs.modal',function(){
			search();
		})
	}

</script>
